use napi_derive_ohos::napi;
use napi_ohos::Error;
use std::fs::{self, File};
use std::io::Write;

/// 创建并写入文件，然后读取文件内容并返回字符串
///
/// 返回：文件内容字符串，或者错误信息
#[napi]
pub fn manage_files() -> Result<String, Error> {
    let mut file = File::create("example.txt").map_err(|e| Error::from_reason(e.to_string()))?;
    file.write_all(b"Hello, Rust File Management!")
        .map_err(|e| Error::from_reason(e.to_string()))?;
    let contents = fs::read_to_string("example.txt").map_err(|e| Error::from_reason(e.to_string()))?;
    Ok(contents)
}

/// 用u32示范接口，返回传入数字加1
#[napi]
pub fn add_one(value: u32) -> u32 {
    value + 1
}

